#include <stdlib.h>
#include <string.h>
#include "math_functions.h"
#include "tools.h"
#include "test.h"
#include "socket_test.h"

typedef void (*ProcessFun)(int argc, char* argv[]);

typedef enum OpCode {
    OpCodeBegin,
    BigEndianTest = OpCodeBegin,
    CTest,
    Sockect,
    //↑ inster new opCode ↑
    OpCodeNum,
} OpCodeE;

typedef struct {
    OpCodeE opCode;
    ProcessFun fun;
    char* info;
} OperateT;

OperateT g_operations[OpCodeNum] = {
   [BigEndianTest] = {BigEndianTest,IsBigEndian,"judge is big endian"},
   [CTest] = {CTest,RunTest,"C program test"},
   [Sockect] = {Sockect,RunSktTest, "socket test"} ,
};

void ExeOpCodeFun(int argc, char* argv[])
{
    if (argc < 2) {
        printf("############ enter a parameter from %d to %d !!! ############\n", OpCodeBegin, OpCodeNum - 1);
        printf("############ usage ############\n");
        for (int i = 0; i < OpCodeNum; i++) {
            printf("%d:%s\n", i, g_operations[i].info);
        }
        printf("############ usage ############\n");
        return;
    }

    OpCodeE opCode = atoi(argv[1]);
    OperateT operate = g_operations[opCode];
    if (opCode != operate.opCode) {
        printf("opCode missmatch !!!\n");
        return;
    }
    if (operate.fun == NULL) {
        printf("operate is null !!!\n");
        return;
    }
    operate.fun(argc, argv);
}

int main(int argc, char* argv[])
{
    ExeOpCodeFun(argc, argv);

    // if (argc < 3) {
    //     printf("Usage: %s base exponent \n", argv[0]);
    //     return 1;
    // }
    // for (int i = 0; i < argc; i++) {
    //     printf("argv[%d]:%s; ", i, argv[i]);
    // }
    // printf("\n");
    // if (strcmp(argv[2], "+") == 0) {
    //     int a = atoi(argv[1]);
    //     int b = atoi(argv[3]);
    //     printf("%d+%d=%d\n", a, b, Add(a, b));
    // }
}
